package org.ly817.learn.mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.ly817.learn.mybatis.entity.User;
import org.ly817.learn.mybatis.mapper.UserMapper;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author LuoYu
 * @date 2019/01/08 9:51
 * <p>
 * Description:
 * 入口测试类
 */
public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("mybatis.xml");
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        SqlSessionFactory factory = builder.build(inputStream);
        try (SqlSession sqlSession = factory.openSession()) {
            UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
            User user = userMapper.getUserById(1L);
            System.out.println(user);
//        List users = sqlSession.selectList("org.ly817.learn.mybatis.mapper.UserMapper.getUserById",1L);
//        System.out.println(users.size());
        }
    }
}
